<?php
include('../../include/report.inc.php');
include('../../include/functions.inc.php');

$strWhere = '';
if (isset($_POST['chkLunes'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.LUNES = 1';
}
if (isset($_POST['chkMartes'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.MARTES = 1';
}
if (isset($_POST['chkMiercoles'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.MIERCOLES = 1';
}
if (isset($_POST['chkJueves'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.JUEVES = 1';
}
if (isset($_POST['chkViernes'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.VIERNES = 1';
}
if (isset($_POST['chkSabado'])) {
    $strWhere .= empty($strWhere) ? '' : ' OR ';
    $strWhere .= 'A.SABADO = 1';
}

$strWhere = empty($strWhere) ? 'A.Lunes = 1 OR A.Martes = 1 OR A.MIERCOLES = 1 OR A.JUEVES = 1 OR A.VIERNES = 1 OR A.SABADO = 1' : $strWhere;

$report = new Report;
$now = date("Y-m-d");
$sql = "SELECT  A.FK_COURSE,
                B.NAME,
                LTRIM(concat(IF(A.LUNES=1,' LUNES ',''),IF(A.MARTES=1,' MARTES ',''),
                    IF(A.MIERCOLES=1,' MIERCOLES ',''),IF(A.JUEVES=1,' JUEVES ',''),
                    IF(A.VIERNES=1,' VIERNES ',''),
                    IF(A.SABADO=1,' SABADO ',''))) DIAS,
                DATE_FORMAT(A.DATE_START, '%d-%m-%Y') DATE_START,
                DATE_FORMAT(A.DATE_END, '%d-%m-%Y') DATE_END,
                A.TIME_BEGIN,
                A.TIME_END,
                A.FK_TEACHER,
                C.FIRST_NAME,
                C.LAST_NAME,
                A.SECTION 
        FROM    cllg_teacher_assign A,
                cllg_courses_catalog B,
                cllg_teacher C
        WHERE   A.FK_COURSE=B.CODE 
        AND     A.FK_TEACHER=C.ID
        AND     A.DATE_END > " . sqlValue($now, "date") . "
        AND     ({$strWhere}) 
        ORDER   BY DIAS,
                A.SECTION,
                A.TIME_BEGIN  ASC";
$report->sql = $sql;
$report->dbManager = $db;
$report->campos = array(
    "NAME" => "CURSO",
    "DIAS" => "DIAS",
    "TIME_BEGIN" => "HORA INICIO",
    "TIME_END" => "HORA FIN",
    "DATE_START" => "FECHA DE INICIO",
    "DATE_END" => "FECHA FINALIZACION",
    "FIRST_NAME" => "NOMBRE CAT.",
    "LAST_NAME" => "APELLIDO CAT.",
    "SECTION" => "SECCION");
$report->requireFilter = false;
$report->ajax = false;
$report->preLoaded = true;
$report->titulo = "Calendario de Estudios";
$_SESSION[$report->sessionName] = serialize($report);
//$report->ready();
$report->load();

//drawDebug($report->sql);
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $report->titulo; ?></title>
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../css/reports.css" rel="stylesheet" type="text/css" />
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../bootstrap/js/bootstrap.js"></script>
    </head>
    <body>
        <div id="filter">
            <form id="report" name="report" method="POST">
                <input  type="hidden" name="flag" value="do"/>
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>
                            <input type="checkbox" name="chkLunes" value="1" <?php print isset($_POST['chkLunes']) ? 'checked="checked"' : ''; ?> />&nbsp;Lunes
                        </td>
                        <td>
                            <input type="checkbox" name="chkMartes" value="1" <?php print isset($_POST['chkMartes']) ? 'checked="checked"' : ''; ?> />&nbsp;Martes
                        </td>
                        <td>
                            <input type="checkbox" name="chkMiercoles" value="1" <?php print isset($_POST['chkMiercoles']) ? 'checked="checked"' : ''; ?> />&nbsp;Mi&eacute;rcoles
                        </td>
                        <td>
                            <input type="checkbox" name="chkJueves" value="1" <?php print isset($_POST['chkJueves']) ? 'checked="checked"' : ''; ?> />&nbsp;Jueves
                        </td>
                        <td>
                            <input type="checkbox" name="chkViernes" value="1" <?php print isset($_POST['chkViernes']) ? 'checked="checked"' : ''; ?> />&nbsp;Viernes
                        </td>
                        <td>
                            <input type="checkbox" name="chkSabado" value="1" <?php print isset($_POST['chkSabado']) ? 'checked="checked"' : ''; ?> />&nbsp;S&aacute;bado
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6" align="center">
                            <br/><input name="buscar" type="submit" class="btn btn-info" id="1" value="Buscar" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <?php
        //echo $report->sql;
        echo $report->buildTable("table table-striped table-hover table-bordered", "data line0", "data line1");
        ?>
    </body>
</html>